import 'babel-polyfill'
import Vue from 'vue'
import App from '@/App'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
import '@/element-ui'                         // api: https://github.com/ElemeFE/element
import '@/icons'                              // api: http://www.iconfont.cn/
import 'element-ui/lib/theme-chalk/index.css'
// 主题样式
import '@/element-ui-theme'
import '@/assets/scss/index.scss'
import tableStyle from '@/element-ui-theme/tableStyle.js'
Vue.use(tableStyle)
// axios请求
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import httpblob from '@/utils/httpblob'
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep';
// 支持IE
import Blob from './excel/Blob'
import Export2Excel from './excel/Export2Excel.js'
// 拖拽组件
import dragAndDrop from '@/components/drag-and-drop'
Vue.component('dragdrop', dragAndDrop)

// 时间组件
import myTime from '@/components/time-component'
Vue.component('myTime', myTime)

// 自定义提示组件
import myTips from '@/components/prompt-information'
Vue.component('myTips', myTips)

// 黑白名单组件
import BlackWhiteList from '@/components/black-white-list'
Vue.component('BlackWhite', BlackWhiteList)

// export const eventBus = new Vue()
//通用函数
import base from '@/base'
Vue.use(base)


//加密
import md5 from 'js-md5'
Vue.prototype.$md5 = md5

// 打印
import printJS from '@/utils/printJS/src/index';
Vue.prototype.$printJS = printJS;
// 打印样式封装
import pringStyle from '@/utils/printJS/src/pringStyle';
Vue.use(pringStyle)

// 时间转化
import timeStr from '@/utils/timeStr';
Vue.use(timeStr)


Vue.use(VueCookie)
Vue.config.productionTip = false

// 非生产环境, 适配mockjs模拟数据                 // api: https://github.com/nuysoft/Mock
if (process.env.NODE_ENV !== 'production') {
  require('@/mock')
}
//路由拦截
router.beforeEach((to, from, next) => {
  let administrator =sessionStorage.getItem("administrator");
  if(administrator){
    next()
  }else{
    if(to.name!=='login'){
      next('/login')
    }else{
      next()
    }
  }
})

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.isAuth = isAuth     // 权限方法
Vue.prototype.$httpblob = httpblob
Vue.prototype.$timeout = 1000 * 60 * 1;

// 加载滚动条
import { Loading } from 'element-ui'
Vue.prototype.Loading = Loading;
// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App },
})
